/******************* (C) COPYRIGHT 2022 CHU WEI TENG ***********************************************
**
**------------------ File Info ---------------------------------------------------------------------
** File name:      dwin_button.c
** modified Date:  2022-05-10
** Last Version:   V1.0
** Descriptions: 
** 
**------------------ Modfication  log --------------------------------------------------------------
** Date       Who            Rev        Comments
----------------------------------------------------------------------------------------------------
   22/05/10 chuwt@qq.com    V1.00      created

****************************************************************************************************/
#include "dwin_button.h"
#include "dwin_trans.h"

/* Private define----------------------------------------------------------------------------------*/

/* Private typedef---------------------------------------------------------------------------------*/

/* Private variables-------------------------------------------------------------------------------*/
static ret_t button_event_dispatch(dwin_widget_t* button, void* ctx);

dwin_widget_vtable_t  button_vt = 
{
    .obj_size = sizeof(dwin_button_t),
    .dispatch = button_event_dispatch,
};

/* public function--------------------------------------------------------------------------------*/
dwin_widget_t* dwin_button_create(dwin_widget_t* parent, uint16_t addr, uint16_t attr, uint16_t size)
{
    dwin_widget_t* button = dwin_widget_create(parent, &button_vt, 0);

    if (button != NULL)
    {
        button->active = 1;
        button->addr = addr;
        button->attr = attr;
        button->size = size;
        button->widget_type = DWIN_BUTTON;
    }
    return button;
}

/* Private function-------------------------------------------------------------------------------*/
static ret_t button_event_dispatch(dwin_widget_t* button, void* ctx)
{
    dwin_button_t* obj = (dwin_button_t *)button;
    data_pack_t*   pack = (data_pack_t *)ctx;
	
	obj->reg_id = (pack->addr_high << 8) | pack->addr_low;
	 
    if (button->func != NULL)
    {
        button->func(button);
    }
    return RET_OK;
}







